# list data in db

# if parameter "id" is not null, then return the data whose uuid == id

# if parameter "id" is null, then return all the data in jaso format

# the format to return data:
# {"content":"",datatime=""}
# or a list of above object



import cgi, cgitb
cgitb.enable()
import os, sys

sys.path.append(os.path.join(os.path.dirname(__file__), 'lib'))

import utils
from entity import Data
from entity import Segment
from datetime import datetime
from google.appengine.ext import db





# get value from parameter
form = cgi.FieldStorage()


uuid = form.getvalue("id")
op = form.getvalue("op")
tzoffset = form.getvalue("tzoffset")

# common output
print "Content-Type: text/plain"
print ""


# business logic

if op == "list":
  if uuid is None:
    print utils.listAllData(tzoffset)
  else:
    print utils.listDataById(uuid,tzoffset)
elif op == "build":
  if uuid is None:
    utils.buildAllData()
    print utils.listAllData(tzoffset)
  else:
    utils.buildDataById(uuid)
    print utils.listDataById(uuid,tzoffset)
else:
  print "no operation is given."




